package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.TodayWeituoModel;
import com.jkc.xh.utils.Tool;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_today_weituo)
public class TodayWeituoItemView extends RelativeLayout {


    @ViewById(R.id.itemName)
    TextView itemName;

    @ViewById(R.id.itemCode)
    TextView itemCode;

    @ViewById(R.id.itemPrice)
    TextView itemPrice;

    @ViewById(R.id.itemFoward)
    TextView itemFoward;

    @ViewById(R.id.itemCount)
    TextView itemCount;

    @ViewById(R.id.itemBuyCount)
    TextView itemBuyCount;

    @ViewById(R.id.itemRevokeCount)
    TextView itemRevokeCount;

    @ViewById(R.id.itemPriceNow)
    TextView itemPriceNow;

    @ViewById(R.id.itemStatus)
    TextView itemStatus;
    @ViewById(R.id.create_time)
    TextView create_time;


    public TodayWeituoItemView(Context context) {
        super(context);
    }

    public TodayWeituoItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(TodayWeituoModel model) {
        itemName.setText(model.stock_name);
        itemCode.setText(model.stock_code);
        if ("1".equals(model.entrust_bs)) {
            itemFoward.setText("买");
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            itemFoward.setText("卖");
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
        itemPrice.setText(model.entrust_price);
        itemCount.setText(model.entrust_amount);
        itemBuyCount.setText(model.business_amount);
        itemRevokeCount.setText(model.cancel_amount);
        itemPriceNow.setText(model.last_price);
        itemStatus.setText(model.status);
        create_time.setText(Tool.formatSecondSimpleFullDate(Long.valueOf(model.create_time)));
    }


    private void setAllTextColor(int textColorId) {
        itemName.setTextColor(textColorId);
        itemCode.setTextColor(textColorId);
        itemFoward.setTextColor(textColorId);
        itemCount.setTextColor(textColorId);
        itemBuyCount.setTextColor(textColorId);
        itemRevokeCount.setTextColor(textColorId);
        itemPriceNow.setTextColor(textColorId);
        itemStatus.setTextColor(textColorId);
        itemPrice.setTextColor(textColorId);
        create_time.setTextColor(textColorId);
    }
}
